package com.example.weight;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.judge.camera.CameraActivity;
import com.judge.camera.CameraActivityKt;

public class MainActivity extends AppCompatActivity {

    private static final int request_code = 101;
    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);

        imageView = findViewById(R.id.iv_re_in_hand);
        imageView.setLayoutParams(new RelativeLayout.LayoutParams(BitmapFactory.decodeResource(getResources(),R.mipmap.shouchishenfenzheng).getWidth(),BitmapFactory.decodeResource(getResources(),R.mipmap.shouchishenfenzheng).getHeight()));
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(MainActivity.this, CameraActivity.class);
//                startActivityForResult(intent, request_code);
//                CameraActivityKt.takeMultiplePhoto(MainActivity.this, request_code, null);
                CameraActivityKt.takeOnePhoto(MainActivity.this, request_code, true);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode != RESULT_OK){
            return;
        }
        if(requestCode == request_code){
            Glide.with(this).load(data.getStringExtra(CameraActivityKt.KEY_IMAGE)).into(imageView);
//            imageView.setImageBitmap(BitmapFactory.decodeFile(data.getStringExtra(CameraActivityKt.KEY_IMAGE)));
        }
    }

    //    // Example of a call to a native method
//    RecyclerView tv = (RecyclerView) findViewById(R.id.rcl_content);
//        List<String> data = new ArrayList<>();
//        data.add("1");
//        data.add("2");
//        data.add("3");
//        data.add("4");
//        BankListAdapter adapter = new BankListAdapter(this,data);
//        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
//        tv.setLayoutManager(mLayoutManager);
////如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
//        tv.setHasFixedSize(true);
//        tv.setAdapter(adapter);
//    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
//    public native String stringFromJNI();

    // Used to load the 'native-lib' library on application startup.
//    static {
//        System.loadLibrary("native-lib");
//    }
}
